package com.ruoyi.patrol.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.patrol.service.IPtFormFillingService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.domain.SysLogininfor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtFormFilling;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单填报学校Controller
 *
 * @author lkm
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/patrol/filling")
public class PtFormFillingController extends BaseController
{
    @Autowired
    private IPtFormFillingService ptFormFillingService;

    /**
     * 查询单填报学校列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:filling:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtFormFilling ptFormFilling)
    {
        startPage();
        List<PtFormFilling> list = ptFormFillingService.selectPtFormFillingList(ptFormFilling);
        return getDataTable(list);
    }

    /**
     * 查询单个填报学校列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:singlefilling:list')")
    @GetMapping("/singlist")
    public TableDataInfo singlelist(PtFormFilling ptFormFilling)
    {
        startPage();
        Long schoolId = SecurityUtils.getSchoolId();
        System.out.println("学校id=-----------"+schoolId);
/*        if (schoolId==null){
            throw new RuntimeException("没有绑定学校，无法查看");
        }*/
        ptFormFilling.setSchoolId(schoolId);
        List<PtFormFilling> list = ptFormFillingService.selectSinglePtFormFillingList(ptFormFilling);
        return getDataTable(list);
    }

    /**
     * 查询单个填报学校列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('patrol:singlefilling:list')")
    @GetMapping("/singlist/nopage")
    public List<PtFormFilling> singlelistNoPageNoFill()
    {
        PtFormFilling ptFormFilling = new PtFormFilling();
        ptFormFilling.setFillType(0L);
        Long schoolId = SecurityUtils.getSchoolId();
        ptFormFilling.setSchoolId(schoolId);
        List<PtFormFilling> list = ptFormFillingService.selectSinglePtFormFillingList(ptFormFilling);
        return list;
    }

    /**
     * 导出单填报学校列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:filling:export')")
    @Log(title = "单填报学校", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtFormFilling ptFormFilling)
    {
        List<PtFormFilling> list = ptFormFillingService.selectPtFormFillingList(ptFormFilling);
        ExcelUtil<PtFormFilling> util = new ExcelUtil<PtFormFilling>(PtFormFilling.class);
        return util.exportExcel(list, "filling");
    }

    /**
     * 获取单填报学校详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:filling:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ptFormFillingService.selectPtFormFillingById(id));
    }

    /**
     * 修改单填报学校
     */
    @PreAuthorize("@ss.hasPermi('patrol:filling:edit')")
    @Log(title = "单填报学校", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtFormFilling ptFormFilling)
    {
        return toAjax(ptFormFillingService.updatePtFormFilling(ptFormFilling));
    }

    /**
     * 删除单填报学校
     */
    @PreAuthorize("@ss.hasPermi('patrol:filling:remove')")
    @Log(title = "单填报学校", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptFormFillingService.deletePtFormFillingByIds(ids));
    }
}
